package com.ibiaoke.boss.controller;


import com.ibiaoke.boss.service.WxPayService;
import com.ibiaoke.common.base.BaseController;
import com.ibiaoke.common.consts.WeChatConsts;
import com.ibiaoke.common.response.Res;
import com.ibiaoke.common.utils.AssertUtils;
import com.ibiaoke.customer.consts.PayTypeConst;
import com.ibiaoke.customer.entity.Customer;
import com.ibiaoke.order.service.OrderPayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.util.Map;

@Controller
public class WxPayController extends BaseController{


    @Autowired
    private WxPayService wxPayService;

    @Autowired
    private OrderPayService orderPayService;

    /**
     * 门店自提
     *
     * @param shopId
     * @param cash
     * @return
     */
    @RequestMapping("/wxOffLinePay")
    @ResponseBody
    public Res offLinePay(Integer shopId, BigDecimal cash, Integer payType, String smsCode) {
        Customer customer = getLoginUser();
        String openId = (String) getSession().getAttribute(WeChatConsts.OPEN_ID);
        AssertUtils.notNull(customer, "请先登录");
        if (payType == PayTypeConst.WECAHT) {
            Map<String, String> payInfo = wxPayService.offLinePay(shopId, cash, customer, openId);
            return Res.create().addResponse("payInfo", payInfo);
        } else if (payType == PayTypeConst.DEPOSIT) {
            orderPayService.offLinePayByDeposit(shopId, cash, customer, smsCode);
            return Res.create();
        } else if(payType == PayTypeConst.ALIPAY){
            String form = wxPayService.offLinePayByAli(shopId, cash, customer);
            return Res.create().addResponse("form", form);
        }
        return Res.create();
    }

}
